package com.fattyCorps.account.controller;


import com.fattyCorps.account.obj.msg.SRet;
import com.fattyCorps.account.obj.msg.client.login.CLoginMsg;
import com.fattyCorps.account.obj.msg.client.login.CModifyMsg;
import com.fattyCorps.account.obj.msg.client.login.CRegMsg;
import com.fattyCorps.account.obj.msg.client.login.CInfoMsg;
import com.fattyCorps.account.service.LoginService;
import com.fattyCorps.common.obj.msg.server.login.SInfoMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    LoginService loginService;

    // 注册
    @PostMapping("/reg")
    public SRet reg(@RequestBody CRegMsg cRegMsg){
        SRet reg = loginService.reg(cRegMsg.getAccount(), cRegMsg.getPassword());
        return reg;
    }

    // 登录
    @PostMapping("/login")
    public SRet login(@RequestBody CLoginMsg cLoginMsg){
        SRet login = loginService.login(cLoginMsg.getAccount(), cLoginMsg.getPassword());
        return login;
    }

    // 修改密码
    @PostMapping("/modify")
    public SRet modify(@RequestBody CModifyMsg cModifyMsg){
        return loginService.modify(cModifyMsg.getAccount(), cModifyMsg.getRawPassword(), cModifyMsg.getNewPassword());
    }

    // 验证token
    @PostMapping("/info")
    public SRet info(@RequestBody CInfoMsg cInfoMsg){
        SInfoMsg info = loginService.info(cInfoMsg.getToken());
        return SRet.success(info);
    }
}